package stack;

import linearList.SeqList;

/**
 * 顺序表实现栈操作，入栈、出栈采用尾插入、尾删除
 * @param <T>
 */
public class SeqStack<T> implements Stack<T> {
    private SeqList<T> list;

    public SeqStack() {
        this(64);
    }

    public SeqStack(int length) {
        this.list = new SeqList<T>(length);
    }

    public String toString() {
    	return this.list.toString();
    }

    @Override
    public boolean isEmpty() {
        return this.list.isEmpty();
    }

    @Override
    public void push(T x) {
   //入栈从尾部插入
   //直接调用Seqlist尾插方法
    	this.list.insert(x);
    }

    @Override
    public T peek() {
        return null;
    }

    @Override
    public T pop() {
    	//出栈从尾部删除
        return this.list.remove(list.size()-1);
    }

    public static void main(String args[]) {
        SeqStack<Character> stack1 = new SeqStack<Character>(20);
        System.out.print("SeqStack Push: ");
        char[] array = {'a', 'b', 'c', 'd', 'e'};
        for (char ch : array) {
 //**********************************************//
            stack1.push(ch);
            System.out.print(ch + "  ");
        }
        System.out.println();
        System.out.print("SeqStack Pop: ");
//**********************************************//
        while (!stack1.isEmpty())
//**********************************************//
            System.out.print(stack1.pop().toString() + "  ");
        System.out.println();

    }

}
